/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			pglayglob.h
  \date			Sep 2012
  \author		TNick

  \brief		Contains the definition for PgLayGlob class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PGLAYGLOB_INC__
#define __PGLAYGLOB_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<cpg/logic/pglayer.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

namespace	cpg		{


class	CpgDoc;

/**
*	@brief	The representation for the global layer
*
*	For an overview of the layers see \ref layers "dedicated page".
*/
class PgLayGlob		: public PgLayer		{
	BBM_TRACK( PgLayGlob );

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	friend class	CpgDoc;
	friend class	ALayID;

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:

	/**
	*	@brief	associated document
	*/
	CpgDoc *				doc_;


	/**
	*	@brief	my index cached to access items list in each space
	*/
	int					idx_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	PgLayGlob					( CpgDoc * doc )
		: PgLayer()
	{
		idx_ = -1;
		doc_ = doc;
	}


	/**
	*	@brief	constructor; clones the other layer
	*/
	PgLayGlob					( CpgDoc * doc, PgLayer * layer );


	/**
	*	@brief	destructor;
	*/
	virtual ~PgLayGlob			( void );


	/**
	*	@brief	tell if this layer is global or associated with a space
	*/
	bool				isGlobal				( void ) const
	{ return true; }


	/**
	*	@brief	get associated document
	*/
	CpgDoc *				document				( void ) const
	{ return doc_; }


	/**
	*	@brief	get the PgItTree of items belonging to this layer in provided space
	*/
	PgItTree *			items					( PgSpace * spc );


	/**
	*	@brief	the index of this one in the PgItTree of layers
	*/
	inline int			globalIndex				( void )
	{ return idx_; }


	/**
	*	@brief	get the limits of the objects in this layer, in specified space
	*/
	bool				extents					(
			PgSpace *			spc,
			ABOX2D &			r
			);


protected:


	/**
	*	@brief	the index of this one in the PgItTree of layers
	*/
	inline void			setGlobalIndex			( int i )
	{ idx_ = i; }


	/**
	*	@brief	add an item to layer's PgItTree in provided space
	*/
	bool				addItem					( PgSpace * spc, PgItem * itm );


	/**
	*	@brief	remove an item from layer's PgItTree in provided space
	*/
	bool				remItem					( PgSpace * spc, PgItem * itm );


	/**
	*	@brief	extract myself from the document's chain of layers
	*
	*	The PgItTree of items from each space is also removed and added to
	*	the argument PgItTree.
	*/
	void				forceExtractFromDoc		( QList<PgItTree*> & items );


	/**
	*	@brief	insert myself in the document's chain of layers
	*
	*	PgItTrees of items for each space are also inserted from argument.
	*	If the list is empty the method inserts NULL as placeholder in
	*	each space.
	*
	*/
	void				forceInsertInDoc		( const QList<PgItTree*> & items );


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PgLayGlob	*/

/*  CLASS    =============================================================== */
//
//
//
//

}	//	namespace	cpg

#endif // __PGLAYGLOB_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
